package com.coollang.smartbra.dialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.coollang.smartbra.R;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/11/30 0030.
 */

public class ShareBitmapDialog extends Dialog implements View.OnClickListener {

    @BindView(R.id.share_radio_web)
    RadioGroup share_radio_web;
    @BindView(R.id.cancel)
    TextView cancel;
    @BindView(R.id.rb_weixin)
    RadioButton rbWeixin;
    @BindView(R.id.rb_pengyouquanshare)
    RadioButton rbPengyouquanshare;
    @BindView(R.id.rb_qq)
    RadioButton rbQq;
    @BindView(R.id.rb_weibo)
    RadioButton rbWeibo;
    private Context mContext;
    /**
     * 分享内容
     */
    Bitmap bitmap;

    public ShareBitmapDialog(Context context, Bitmap bitmap) {
        super(context, R.style.dialog);
        mContext = context;
        this.bitmap = bitmap;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_share);
        ButterKnife.bind(this);
        initView();
    }

    private void initView() {
        cancel.setOnClickListener(this);
        rbWeixin.setOnClickListener(this);
        rbPengyouquanshare.setOnClickListener(this);
        rbQq.setOnClickListener(this);
        rbWeibo.setOnClickListener(this);
    }

    @Override
    public void show() {
        Window window = this.getWindow();
        window.setWindowAnimations(R.style.dialog_enter_exit); // 添加动画
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        window.getDecorView().setPadding(0, 0, 0, 0);
        // 以下这两句是为了保证按钮可以水平满屏
        lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
        lp.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        // 设置显示位置
        this.onWindowAttributesChanged(lp);
        window.setGravity(Gravity.BOTTOM);// 居底
        // 设置点击外围解散
        this.setCanceledOnTouchOutside(true);
        super.show();
    }

    @Override
    public void onClick(View v) {

        if (mOnclickListener == null)
            return;

        switch (v.getId()) {
            case R.id.cancel:
                mOnclickListener.onCancel();
                break;
            case R.id.rb_weixin:
                mOnclickListener.onWeixin();
                break;
            case R.id.rb_pengyouquanshare:
                mOnclickListener.onWEXIN_CIRCLE();
                break;
            case R.id.rb_qq:
                mOnclickListener.onQQ();
                break;
            case R.id.rb_weibo:
                mOnclickListener.onWeibo();
                break;
            default:
                break;
        }
        this.dismiss();
    }

    public interface OnclickListener {
        void onCancel();

        void onWeixin();

        void onWEXIN_CIRCLE();

        void onWeibo();

        void onQQ();
    }

    private OnclickListener mOnclickListener;

    public void setOnclickListener(OnclickListener onclickListener) {
        mOnclickListener = onclickListener;
    }
}
